#!/usr/bin/env python
#__description__"这是一个二分法查找数字的实现
#__time__: 2018/4/24 11:55
#__author__: leetone123
#__file__: binary_search.py
def search(sequence,number,lower=0,upper=None):
    if upper is None : upper = len(sequence) -1
    if lower == upper :
        assert number == sequence[upper]
        return upper
    else:
        middle = (lower+upper) //2
        if number > sequence[middle]:
            return search(sequence,number,middle+1,upper)
        else:
            return search(sequence,number,lower,middle)
#下面开始测试
seq = [22,5,98,53,54,75,21,26,2,15,49]
seq.sort()
print(seq)
print(search(seq,54))
print(search(seq,98))